const { ccclass, property } = cc._decorator;
import ecsComponent from '../app/ecs/ecsComponent';
@ccclass
export default class jumpComponent extends ecsComponent {
    constructor() {
        // 此处super传入ecsName值, 规定Component及Entity所属(默认default)
        super(/*other*/);
    }
    private dt = 0;

    public height = 200;
    public speed = 400;
    public downScaleX = 2;
    public downScaleY = 0.5;
    public jumpScaleX = 0.5;
    public jumpScaleY = 2;

    public set jumpY(v) {
        this.node.y = v;
    }

    public set scaleX(v) {
        this.node.scaleX = v;
    }

    public set scaleY(v) {
        this.node.scaleY = v;
    }

    private _time = 0;
    public get time() {
        if (!this._time) {
            this._time = this.height / this.speed;
        }
        return this._time;
    };

    public get radio() {
        if (this.dt > this.time) {
            return 2 - this.dt / this.time;
        } else {
            return this.dt / this.time;
        }
    }

    protected ecsUpdate(dt: number) {
        this.dt += dt;
        if (this.dt >= this.time * 2) {
            this.dt -= this.time * 2;
        }
    }
}